import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @License: (C) Copyright 2013-2022
 * @Contact: abcque@outlook.com
 * @IDE: IntelliJ IDEA
 * @Encoding: utf-8
 * @Project: st2214st2215
 * @Package: PACKAGE_NAME
 * @File: ReadFile.java
 * @Time: 2023/4/25 14:48
 * @Author: abcque
 * @Description:
 * @Modifier:
 * @ModifyDate:
 * @ModifyRemark:
 */
public class ReadFile {
    public static void main(String[] args) {
        try {
            FileReader reader = new FileReader("stream.txt");
            /*// 一次读取一个字符
            char read = (char) reader.read();
            System.out.println("您读取了：" + read);
            read = (char) reader.read();
            System.out.println("您读取了：" + read);
            read = (char) reader.read();
            System.out.println("您读取了：" + read);*/

            /*char[] temp = new char[1024];
            // reader.read(temp);
            // for (char c : temp) {
            //     System.out.println(c);
            // }

            // 从文件中读取内容到 temp 数组，并返回读取的字符个数
            int length = reader.read(temp);
            for (int i = 0; i < length; i++) {
                System.out.println(temp[i]);
            }*/

            char[] temp = new char[8];
            int length = 0;

            while ((length = reader.read(temp)) != -1){
                String string = new String(temp, 0, length);
                System.out.println(string);
            }

            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
